<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="my.market.jdbc.dao.*" %>
<%@ page import="my.market.jdbc.dataClass.*" %>
<%@ page import="java.util.List" %>

<%	String nameString = request.getParameter("name");

	UsersDao ud = new UsersDao();
	HistoryDao hd = new HistoryDao();
	GoodsDao gDao = new GoodsDao();
	List<History> histories = null;
	if(nameString != null && !nameString.equals("")){
		Users user = ud.findUserByName(nameString);
		histories = hd.getHistory(user.getMail());
	}
	 %>
<html>
<head>
<script type="text/javascript">
function click_func(obj, myid){
	if (document.getElementById(myid).value == document.getElementById(myid).defaultValue){
	  document.getElementById(myid).value = '';
	  obj.style.color='#000';
	}
}
function blur_func(obj, myid){
	if (document.getElementById(myid).value == ''){
	 document.getElementById(myid).value = document.getElementById(myid).defaultValue;
	 obj.style.color='#666';
 }
}
</script>
</head>
<body>
<p align="left">记录查询<br/><br/><br/></p>
<form action="${pageContext.request.contextPath}/back_end/display/history.jsp" method="post">
<table>
	<tr>
		<td><input type="text" name="name" id="name" value="请输入将要查询的姓名"
				onmouseover="this.focus();" 
				onclick="click_func(this, 'name');" 
				onBlur="blur_func(this, 'name');"></td>
		<td><input type="submit" value="查询"></td>
	</tr>
</table>
</form>
<table>
<%if(histories != null){%>
	<tr><td><%=request.getParameter("name") %>的历史记录</td></tr>
	<tr>
		<td align="center" width="24%">浏览时间</td>
		<td align="center" width="18%">商品名称</td>
		<td align="center" width="9%">商品价格</td>
		<td width="8%" align="center">商品类别</td>
	</tr>
	<%for(int i=0; i<histories.size(); i++){
		History his = histories.get(i);
		int tmp = his.getGoods_id();
		String id = Integer.toString(tmp);
		Goods good = gDao.findGoodById(id);	%>
		<tr onmouseover="this.style.backgroundColor = 'white'"
			onmouseout="this.style.backgroundColor = '#F5FAFE';">
			<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="200"><%=his.getBrowse_time() %></td>
			<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="18%"><%=good.getName() %></td>
			<td style="CURSOR: hand; HEIGHT: 22px" align="center" width="8%"><%=good.getPrice() %></td>
			<td style="CURSOR: hand; HEIGHT: 22px" align="center"><%=good.getType() %></td>
		</tr>
	<% } %>
<% }%>
	<tr>
		<td><a href="${pageContext.request.contextPath}/back_end/display/orders.jsp"><button type="button">返回</button></a></td>
	</tr>
</table>
</body>
</html>